/**
 * @author 黄波
 * 创建日期：2011Sep 1, 2011
 * TODO// N/A
 */
package com.platform.dev.action;

import java.io.PrintWriter;
import java.util.HashMap;

import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;

import org.apache.struts2.ServletActionContext;

import com.platform.dev.bo.DevBo;
import com.platform.pojo.Power;

//修改权限
public class UpdatePowerAction extends DevSupport {

	private String id;
	private String msg;
	private boolean success;
	private Power power;
	
	/**
	 * @return the power
	 */
	public Power getPower() {
		return power;
	}

	/**
	 * @param power the power to set
	 */
	public void setPower(Power power) {
		this.power = power;
	}

	/**
	 * @return the id
	 */
	public String getId() {
		return id;
	}

	/**
	 * @param id the id to set
	 */
	public void setId(String id) {
		this.id = id;
	}

	/**
	 * @return the msg
	 */
	public String getMsg() {
		return msg;
	}

	/**
	 * @param msg the msg to set
	 */
	public void setMsg(String msg) {
		this.msg = msg;
	}

	/**
	 * @return the success
	 */
	public boolean isSuccess() {
		return success;
	}

	/**
	 * @param success the success to set
	 */
	public void setSuccess(boolean success) {
		this.success = success;
	}

	@Override
	public String execute() throws Exception {
		DevBo bo = new DevBo();
		if(power == null || id == null || id.equals("")) {
			msg = "更新失败，请再次尝试！";
			success = false;
		} else {
			power.setId(Integer.parseInt(id));
			if (bo.updatePower(power)) {
				msg = "更新成功！";
				success = true;
			} else {
				msg = "更新失败，服务器异常！";
				success = false;
			}
		}
		HashMap map = new HashMap();
		map.put("msg", msg);
		map.put("success", success);
		JSONObject jsonObj = JSONObject.fromObject(map);
		HttpServletResponse response = ServletActionContext.getResponse();
//		response.setContentType("application/json;charset=UTF-8");
//		response.setCharacterEncoding("utf-8");
//		response.setHeader("Charset", "utf-8");
//		response.setHeader("Cache-Control", "no-cache");
//		response.getWriter().write(jsonObj.toString());
		PrintWriter out = response.getWriter();
		response.setCharacterEncoding("utf-8");
		out.println(jsonObj.toString());
		out.flush();
		return null;
	}

}
